#include<stdio.h>
#include<string.h>

struct student{
    char name[20];
    int id;
	int math;
    int chinese;
    int sum;
};

int main()
{
	int j,i,n,t;
	char b[100];
	struct student member[200];
	scanf("%d",&n);
	for (i=0;i<n;i++)
	{
		scanf("%s",member[i].name);
		scanf("%d",&member[i].id);
		scanf("%d",&member[i].math);
		scanf("%d",&member[i].chinese);
		member[i].sum=member[i].chinese+member[i].math;
	}
	for (i=0;i<n-1;i++)
		for (j=0;j<n-1-i;j++)
			if (member[j].sum<member[j+1].sum)
			{
				strcpy(b,member[j].name);
				strcpy(member[j].name,member[j+1].name);
				strcpy(member[j+1].name,b);
				t=member[j].sum;
				member[j].sum=member[j+1].sum;
				member[j+1].sum=t;
				t=member[j].id;
				member[j].id=member[j+1].id;
				member[j+1].id=t;
			}
	for (i=0;i<n-1;i++)
	{
		if (member[i].sum==member[i+1].sum)
			if (member[i].id>member[i+1].id)
			{
				strcpy(b,member[i].name);
				strcpy(member[i].name,member[i+1].name);
				strcpy(member[i+1].name,b);
				t=member[i].sum;
				member[i].sum=member[i+1].sum;
				member[i+1].sum=t;
			}
	}
	for (i=0;i<n;i++)
		printf("%s %d\n",member[i].name,member[i].sum);
	return 0;
}
